﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace DAMBAOCLPM
{
    class clsConnection
    {
        public static SqlConnection con = new SqlConnection();
        public static string Server = "";
        public static string Database = "";
        public static string uid = "";
        public static string pwd = "";

        public static void CreateConnection()
        {
            string[] mang = new string[4];
            string a;
            int n = 0;
            System.IO.StreamReader docFile = new System.IO.StreamReader("D:\\CAUHINH.txt");
            a = docFile.ReadLine();
            while (a != null)
            {
                mang[n] = a;
                a = docFile.ReadLine();
                n++;
            }
            docFile.Close();
            docFile.Dispose();
            Server = mang[0];
            Database = mang[1];
            uid = mang[2];
            pwd = mang[3];

            
                    string str = "Server=" + Server + ";Database=" + Database + ";uid=" + uid + ";pwd=" + pwd;
                    con = new SqlConnection(str);
                    con.Open();
        }
        public static bool CloseConnection()
        {
            try
            {
                if (con.State != ConnectionState.Closed)
                {
                   
                    con.Close();
                }
                return true;
            }
            catch (Exception)
            {
            }
            return false;
        }

        
    }
}
